package linhnv.app;

import java.util.Date;

import android.content.Context;
import android.os.Debug;
import android.util.Log;
import android.widget.Toast;

public class ShowLog {
	
	// ShowLog Flag (Using turn on or turn off debug)
	private static final boolean IS_FLAG_DEBUG = true;
	private static final boolean IS_FLAG_ERROR = false;
	private static final boolean IS_FLAG_INFO = false;
	private static final boolean IS_FLAG_VERBOSE = false;
	private static final boolean IS_FLAG_WARN = false;
	private static final boolean IS_FLAG_OS = false;
	private static final boolean IS_FLAG_TOAST = false;
	
	/**
	 * Contact value is 3
	 * Show Log Debug. Data note flow page.
	 * @param tag Prefix
	 * @param message Debug message
	 */
	public static void showLogDebug(String tag, String message){
		if(IS_FLAG_DEBUG){
			Log.d(tag, message);
		}
	}
	
	/**
	 * Contact value is 6
	 * Show Log Error. Data very important, use to start to end block or end point to redirect page
	 * @param tag Prefix
	 * @param message Debug message
	 */
	public static void showLogError(String tag, String message){
		if(IS_FLAG_ERROR){
			Log.e(tag, message);
		}
	}
	
	/**
	 * Contact value is 4
	 * Show Log Info. Data show result
	 * @param tag Prefix
	 * @param message Debug message
	 */
	public static void showLogInfo(String tag, String message){
		if(IS_FLAG_INFO){
			Log.i(tag, message);
		}
	}
	
	/**
	 * Contact value is 2
	 * Show Log Verbose. Data show result
	 * @param tag Prefix
	 * @param message Debug message
	 */ 
	public static void showLogVerbose(String tag, String message){
		if(IS_FLAG_VERBOSE){
			Log.i(tag, message);
		}
	}
	
	/**
	 * Contact value is 5
	 * Show Log Warn. Data show result
	 * @param tag Prefix
	 * @param message Debug message
	 */ 
	public static void showLogWarn(String tag, String message){
		if(IS_FLAG_WARN){
			Log.i(tag, message);
		}
	}
	
	/**
	 * Show Log Current Time
	 * @param tag Prefix
	 * @param message Message add more
	 */
	public static void showLogTime(String tag, String message){
		//System.currentTimeMillis
		if(IS_FLAG_OS){
			Date date = new Date();
			String current = date.getMinutes() + ":" + date.getSeconds();
			Log.e(tag, message + " :: Current time now: " + current + " (mm:ss)");
		}
	}
	
	/**
	 * Show Toast
	 * @param context Context of activity
	 * @param message Message show toast
	 */
	public static void showToast(Context context, String message){
		if(IS_FLAG_TOAST){
			Toast.makeText(context, message, Toast.LENGTH_LONG).show();
		}
	}
	
	/**
	 * Show memory message
	 * @param tag
	 * @param message Message show
	 */
	public static void showLogMemory(String tag, String message){
		// Note: android.os.Debug.getNativeHeapAllocatedSize()
		// Link Preferent: http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/
		// http://organicandroid.blogspot.com/2010/12/totalfree-memory-on-android-apps-and.html
		// long maxMem = Runtime.getRuntime().maxMemory();
		
		//String className = ShowLog.getClass().getName();
		
		if(IS_FLAG_OS){
			long allSize = Debug.getNativeHeapAllocatedSize() / 1024; // Origin is BYTES, print out is KB
			long freeSize = Debug.getNativeHeapFreeSize() / 1024;
			long size = Debug.getNativeHeapSize() / 1024;
			long maxMem = Runtime.getRuntime().maxMemory() / 1024; // Max memory
			//Usage
			Log.e(tag, "********** " + message + " :: Memory ********** Max Memory(" + maxMem + " KB) Allocation(" + allSize + " KB)" + " Free(" + freeSize + " KB)" + " Usage(" + size + " KB)");
		}
	}
}

